package com.shuqi.model.parse.parser;

import org.xml.sax.Attributes;

import com.shuqi.common.utils.Log4an;
import com.shuqi.database.model.UserInfo;
import com.shuqi.model.bean.AccountInfo;
import com.shuqi.model.parse.HandlerBase;

public class AccountParser extends HandlerBase {
    private final String logTag = "AccountParser";

    private AccountInfo info;
    private UserInfo user;

    public AccountInfo getParsedData() {
        return info;
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes atts) {
        if ("body".equals(localName)) {
            info = new AccountInfo();
        } else if (localName.equals("serverinfo")) {
            info.setServerState(isNull(atts, "state"));
            info.setServerMessage(isNull(atts, "message"));
        } else if (localName.equals("Unique")) {
            info.setUniqueCode(isNull(atts, "state"));
            info.setUniqueMessage(isNull(atts, "message"));
        } else if (localName.equals("Validate")) {
            info.setValidate(isNull(atts, "state"));
            info.setValidateMessage(isNull(atts, "message"));
            info.setGrade(isNull(atts, "grade"));
        } else if (localName.equals("UserInfo")) {
            user = new UserInfo();
            info.setUser(user);
            info.setUserId(isNull(atts, "userId"));
            user.setUserId(isNull(atts, "userId"));
            user.setNickName(isNull(atts, "nickName"));
            user.setGender(isNull(atts, "gender"));
            user.setSession(isNull(atts, "session"));
        } else if (localName.equals("Wallet")) {
            if (user == null) {
                user = new UserInfo();
            }
            user.setBalance(isNull(atts, "balance"));
        } else if (localName.equals("Bind")) {
            if (user == null) {
                user = new UserInfo();
            }
            String type = isNull(atts, "type");
            if ("1".equals(type)) {
                user.setMobile(isNull(atts, "account"));
//                user.setMobileShow(isNull(atts, "name"));
            } else if ("2".equals(type)) {
                user.setEmail(isNull(atts, "account"));
//                user.setEmailShow(isNull(atts, "name"));
            } else if ("3".equals(type)) {
                user.setSinaKey(isNull(atts, "account"));
                user.setSinaName(isNull(atts, "name"));
            } else {
                Log4an.e(logTag, "error bind type=" + type);
            }
        }
    }
}
